package com.wuyou.mid;

import com.mysql.cj.util.StringUtils;

public class Reverse {


    public static void main(String[] args) {
        int x = 123;

        System.out.println(solution_1(x));
    }

    public static int solution_2(int x) {
        String s = "" + x;
        StringBuilder sb = new StringBuilder();
        for (int i = s.length() - 1; i > 0; i--) {
            if (s.charAt(i) == '-') {
                continue;
            }
            sb.append(s.charAt(i));
        }

        return 0;
    }

    public static int solution_1(int x) {
        StringBuilder sb = new StringBuilder(String.valueOf(x));
        char c = sb.charAt(0);
        if (sb.charAt(0) < '0' || sb.charAt(0) > '9') {
            sb = new StringBuilder(sb.substring(1, sb.length()));
        }
        sb.reverse();
        int max = Integer.MAX_VALUE;
        int min = Integer.MIN_VALUE;
        if (Long.parseLong(sb.toString()) > max || Long.parseLong(sb.toString()) < min) {
            return 0;
        }
        int res = Integer.parseInt(sb.toString());
        if (c == '-') {
            res *= -1;
        }
        return res;
    }
}
